package cn.luyou.admin.mapper;

import cn.luyou.admin.entity.ExamRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface ExamRecordMapper extends BaseMapper<ExamRecord> {
    
    @Select("SELECT COUNT(*) FROM exam_record WHERE user_id = #{userId}")
    Integer countByUserId(Long userId);
    
    @Select("SELECT AVG(score) FROM exam_record WHERE user_id = #{userId} AND status = 1")
    Double getAverageScore(Long userId);
    
    @Select("SELECT COUNT(*) FROM exam_record_detail d JOIN exam_record r ON d.record_id = r.id WHERE r.user_id = #{userId} AND d.is_correct = false")
    Integer countWrongQuestions(Long userId);
} 